package com.video.netty.commons.utils;

import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

public class MsgUtil {

    private static Map<String, BlockingQueue> msgMap = new ConcurrentHashMap<>();

    /**
     * 根据消息id创建一个阻塞队列
     * @param msgId
     */
    public static void createMsgQueue(String msgId){
        BlockingQueue blockingQueue = new ArrayBlockingQueue(1);
        msgMap.put(msgId, blockingQueue);
    }

    /**
     * 删除阻塞队列
     * @param msgId
     */
    public static void deleteMsgQueue(String msgId){
        if (msgMap.containsKey(msgId)){
            msgMap.remove(msgId);
        }
    }

    /**
     * 根据msgid获得阻塞队列
     * @param msgId
     * @return
     */
    public static BlockingQueue getBlockQueue(String msgId){
        return msgMap.get(msgId);
    }
}
